package com.huxiu.holder;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huxiu.HuaTiDetailActivity;
import com.huxiu.R;
import com.huxiu.net.model.HuaTiItem;
import com.huxiu.utils.Constants;
import com.huxiu.utils.Utils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.lang.ref.WeakReference;


public class WoFaBiaoHolder {

    @ViewInject(R.id.item_wofabiao)
    private LinearLayout itemLine;

    @ViewInject(R.id.wofabiao_item_title)
    private TextView title;

    @ViewInject(R.id.wofabiao_item_time)
    private TextView time;

    @ViewInject(R.id.wofabiao_item_liulan_num)
    private TextView liulanNum;

    @ViewInject(R.id.wofabiao_item_huifu_num)
    private TextView huifuNum;

    private static Activity mContext;
    private static WeakReference<BaseAdapter> mAdapter;

    public void setAdapter(BaseAdapter adapter) {
        mAdapter = new WeakReference<>(adapter);
    }

    public WoFaBiaoHolder(View view, Activity context) {
        ViewUtils.inject(this, view);
        mContext = context;
        itemLine.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, HuaTiDetailActivity.class);
                intent.putExtra(Constants.GROUP_HUATI_ITEM_ID, mItem.id);
                mContext.startActivity(intent);
            }
        });
    }

    private HuaTiItem mItem;

    public void bindItem(HuaTiItem item) {
        mItem = item;
        title.setText(mItem.title);
        time.setText(Utils.getDateString(mItem.time));
        liulanNum.setText(Integer.toString(mItem.view_num) + "人浏览");
        huifuNum.setText(Integer.toString(mItem.comment_num) + "人回复");
    }

}
